{extend name="Public:base"/}

{block name="main"}
{load href="__JS__/preview.js"/}
<style>
    #preview {
        position: absolute;
        border: 1px solid #ccc;
        background: #333;
        padding: 5px;
        display: none;
        color: #fff;
    }

    #preview img {
        width: 200px;
        height: 200px;
    }
</style>

<div class="box-info">
    <div class="table-toolbar">
        <div class="row">
            <div class="col-md-12">
                <a href="{:U($model_name.'/add')}" class="btn btn-primary">添加</a>
                <button class="btn btn-danger" onclick="return confirm_deleteall()">删除</button>
                <button class="btn btn-primary" onclick="myform.action='{:U($model_name.'/sort')}';$('#myform').submit();">排序</button>
                <button class="btn btn-success ajax_post" url="{:U($model_name.'/setStatus','status=1')}">启用</button>
                <button class="btn btn-warning ajax_post" url="{:U($model_name.'/setStatus','status=0')}">禁用</button>
                <button class="btn btn-primary" id="push_btn">推送</button>
                <button class="btn btn-primary" id="content_move">批量移动</button>
            </div>
        </div>
    </div>

    <div class="table-toolbar">
        <div class="row">
            <div class="col-md-12">
                <form class="form-inline" action="{:U($model_name.'/index')}" method="get">
                    <input type="hidden" name="g" value="{$Think.GROUP_NAME}"/>
                    <input type="hidden" name="m" value="{$Think.MODULE_NAME}"/>
                    <input type="hidden" name="a" value="{$Think.ACTION_NAME}"/>

                    <div class="form-group">
                        <input type="text" class="form-control" name="keyword" value="{$keyword}"/>
                    </div>
                    <div class="form-group">
                        <select class="form-control" name="searchtype">
                            {if condition="$fields['title']"}
                            <option value="title" {eq name="searchtype" value='title'}selected="selected" {/eq}>标题</option>
                            {/if}
                            {if condition="$fields['keywords']"}
                            <option value="keywords" {eq name="searchtype" value='keywords'}selected="selected" {/eq}>关键词</option>
                            {/if}
                            <option value="id" {eq name="searchtype" value='id'}selected="selected"{/eq}>ID</option>
                        </select>
                    </div>
                    <div class="form-group">
                        {if condition="$fields['catid']"}
                            <select class="form-control" id="catid" name="catid">
                                <option value="0">选择栏目</option>
                                {$select_categorys}
                            </select>
                        {/if}
                    </div>
                    <div class="form-group">
                        <select class="form-control" id="status" name="map[status]">
                            <option value="">状态</option>
                            <option value="0" {if condition="isset($status) && $status ==0"}selected="selected" {/if}>禁用</option>
                            <option value="1" {if condition="isset($status) && $status ==1"}selected="selected" {/if}>启用</option>
                        </select>
                    </div>
                    <div class="form-group">
                        <select class="form-control" id="order" name="order">
                            <option value="listorder" {eq name="order" value="listorder"}selected="selected" {/eq}>排序</option>
                            <option value="id" {eq name="order" value="id" }selected="selected"{/eq}>ID排序</option>
                            {if condition="$fields['hits']"}
                            <option value="hits" {eq name="order" value="hits" }selected="selected" {/eq}>{:L('hits')}排序</option>{/if}
                        </select>
                    </div>
                    <div class="form-group">
                        <select class="form-control" name="sort">
                            <option value="asc" {if condition="$sort =='asc'" }selected="selected" {/if}>递增</option>
                            <option value="desc" {if condition="$sort =='desc'" }selected="selected" {/if}>递减</option>
                        </select>
                    </div>
                    <div class="form-group">
                        <select class="form-control" name="listRows">
                            <option value="15" {if condition="$listRows ==5" }selected="selected" {/if}>15条每页</option>
                            <option value="20" {if condition="$listRows ==20" }selected="selected" {/if}>20条每页</option>
                            <option value="50" {if condition="$listRows ==50" }selected="selected" {/if}>50条每页</option>
                            <option value="100" {if condition="$listRows ==100" }selected="selected" {/if}>100条每页</option>
                        </select>
                    </div>
                    <input type="submit" value="查询" class="btn btn-primary"/>
                </form>

            </div>
        </div>
    </div>

    <div class="row table-container">
        <div class="col-md-12">
            <form name="myform" id="myform" action="" method="post">
                <input type="hidden" name="catid" value="{$Think.get.catid}">
                <table class="table table-hover table-bordered">
                    <thead>
                    <tr>
                        <th width="50"><input type="checkbox" value="" id="check_box" onclick="selectall('ids[]');"></th>
                        <th width="60">排序</th>
                        <th width="40">ID</th>
                        <th>标题</th>
                        <th>日期</th>
                        <th>状态</th>
                        <th>发布人</th>
                        <th class="center table-cell-2">操作管理</th>
                    </tr>
                    </thead>
                    <tbody>
                    {empty name="list"}
                    <tr class="table-data-empty">
                        <td class="text-center empty-info" colspan="8">
                            <i class="fa fa-database"></i> 暂无数据<br>
                        </td>
                    </tr>
                    {else/}
                    {volist name="list" id="vo" key="k"}
                    <tr>
                        <td width="30" align="center">
                            <input class="inputcheckbox" name="ids[]" value="{$vo['id']}" type="checkbox">
                        </td>
                        <td width="40" align='center'>
                            <input name='listorders[{$vo.id}]' type='text' size='3' value='{$vo.listorder}' class='input-text-c'>
                        </td>
                        <td>{$vo['id']}</td>
                        <td>
                            {if condition="$vo['catid']"}
                            [<font color="green">{$categorys[$vo['catid']]['catname']}</font>]
                            {/if}
                            {$vo['title']}
                            {if condition="$vo['thumb']!=''"}
                            <a href="{$vo['thumb']}" class="preview" title="{$vo['title']}"><img src="__IMG__/admin_image.gif"></a>
                            {/if}
                            {if condition="$vo['posid']!=0"}
                            <img src="__IMG__/admin_elite.gif">
                            {/if}
                        </td>
                        <td>
                            {$vo['create_time']|toDate=###,'Y-m-d'}
                            <?php if($vo['create_time'] >= time()){?>
                            定时发布
                            <?php } else { ?>
                            已发布
                            <?php }?>
                        </td>
                        <td>
                            {if condition="$vo['status']==1"}
                            <font color="green">启用</font>
                            {else/}
                            <a href="{:U($model_name.'/status',array(id=>$vo['id'],status=>1))}">
                                <font color="red">禁用</font></a>
                            {/if}
                        </td>
                        <td>{$vo['username']}</td>
                        <td class="center table-cell-2">
                            <a class="btn btn-sm btn-primary" href="{:U($model_name.'/edit',array('catid'=>$vo['catid'],'id'=>$vo['id']))}">编辑</a>
                            <a class="btn btn-sm btn-danger" href="javascript:confirm_delete('{:U($model_name.'/delete',array('catid'=>$vo['catid'],'id'=>$vo['id']))}')">删除</a>
                        </td>
                    </tr>
                    {/volist}
                    {/empty}
                    </tbody>
                </table>

                <div class="row">
                    <div class="col-md-12">
                        <div class="pull-right pagination">{$page}</div>
                    </div>

                </div>
            </form>
        </div>
    </div>
</div>
{/block}

{block name="script"}
<script>
function confirm_deleteall() {
    var str = 0;
    var id = tag = '';
    $('input[name="ids[]"]:checked').each(function () {
        str = 1;
        id += tag + $(this).val();
        tag = ',';
    });
    if (str == 0) {
        layer.msg('您没有勾选信息，无法进行操作！', {
            icon: 2,
            time: 1000 //2秒关闭（如果不配置，默认是3秒）
        });
        return false;
    }
    layer.confirm("确认要删除信息吗?", function () {
        myform.action = '/Admin/{$model_name}/delete?id='+id;
        $('#myform').submit();
    });
}

$('.ajax_post').click(function(){
    var url = $(this).attr('url');
    var str = 0;
    var id = tag = '';
    $('input[name="ids[]"]:checked').each(function () {
        str = 1;
        id += tag + $(this).val();
        tag = ',';
    });
    if (str == 0) {
        layer.msg('您没有勾选信息，无法进行操作！', {
            icon: 2,
            time: 1000 //2秒关闭（如果不配置，默认是3秒）
        });
        return false;
    }
    $.ajax({
        url: url + '&id=' + id,
        beforeSend: function () {
            layer.msg('处理中');
        },
        success: function (data) {
            if (data.status === 1) {
                window.location.reload();
            } else {
                layer.msg(data.info, {
                    icon: 2,
                    time: 1000 //2秒关闭（如果不配置，默认是3秒）
                });
            }
        }
    });
});

$('#push_btn').click(function () {
    var str = 0;
    var id = tag = '';
    $('input[name="ids[]"]:checked').each(function () {
        str = 1;
        id += tag + $(this).val();
        tag = '|';
    });
    if (str == 0) {
        layer.msg('您没有勾选信息，无法进行操作！', {
            icon: 2,
            time: 1000 //2秒关闭（如果不配置，默认是3秒）
        });
        return false;
    }
    openwin('/Admin/{$model_name}/push?action=position_list&id=' + id,'信息推送','800px','400px');
});

$('#content_move').click(function () {
    var str = 0;
    var id = tag = '';
    $('input[name="ids[]"]:checked').each(function () {
        str = 1;
        id += tag + $(this).val();
        tag = '|';
    });
    if (str == 0) {
        layer.msg('您没有勾选信息，无法进行操作！', {
            icon: 2,
            time: 1000 //2秒关闭（如果不配置，默认是3秒）
        });
        return false;
    }
    openwin('/Admin/{$model_name}/remove?id=' + id,'批量移动','800px','400px');
});

</script>
{/block}